package lab

// HasDuplicatesBy 使用特征值来判断是否有重复元素
func HasDuplicatesBy[T any, K comparable](array []T, fn func(T) K) bool {
	seen := make(map[K]bool)
	for _, v := range array {
		key := fn(v)
		if seen[key] {
			return true
		}
		seen[key] = true
	}
	return false
}
